package user;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.*;
import javax.servlet.http.*;

import com.mysql.jdbc.*;


public class OrderFormItem extends HttpServlet {
	public void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
		String SubmitUpdate = request.getParameter("SubmitUpdate");
		PrintWriter out = response.getWriter();	
		 if (SubmitUpdate != null && SubmitUpdate.length() > 0)
		 {
			DBConnector db = DBConnector.getDBConnector();		
			//String Rest_ID = RestaurantQuery.getRestaurantSelected();
			
			try{
				db.prepareStatement("select max(contain_ID) from contain");
				ResultSet NumContain = db.queryPstmt();
				NumContain.next();
				int iNumContain = NumContain.getInt(1);
				//String sNumOrderForm = NumOrderForm.getString(1);
				int i = 1;
				while (i <= iNumContain)
				{
					String index = "" + i;
					String ContainID = request.getParameter(index);
					if (ContainID != null) //if this form item has been updated
					{
						String statement = "update contain set contain_state = 'done' where contain_ID = " + index;
						db.prepareStatement(statement);
						db.updatePstmt();	
					}
					i++;
				}	
			}catch (Exception ex) {
				System.out.println("OrderFormItem exception");
			}
			out.println("<script>alert(unescape('The form item status update is successful.'))</script>");
			out.println("<script type =\"text/javascript\"> window.location.href = '../restaurant_account.jsp'</script>");
			//response.sendRedirect("../administrator_account.jsp");		
		}		
	}
}
